﻿using BLL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Loginter
{
    public partial class AddTruckTeam : System.Web.UI.Page
    {
        //调用MODEL层的车队数据
        TruckTeamMODEL truckteam = new TruckTeamMODEL();
        //调用BLL层的车队信息
        TruckTeamBLL truck = new TruckTeamBLL();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 重置按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button2_Click(object sender, EventArgs e)
        {
            //车队名称
            txt_TruckName.Text = null;
            //车队负责人
            txt_leader.Text = "";
            //备注
            txt_Remark.Text = "";
            //提示信息
            lable.Text = "";
        }

        /// <summary>
        /// 添加按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            //车队名称
            string tname = txt_TruckName.Text.Trim();
            //负责人
            string lname = txt_leader.Text.Trim();
            //备注
            string rt = txt_Remark.Text.Trim();
            //当前的时间
            string time = DateTime.Now.ToShortDateString();
            //调用MODEL层的车队信息
            TruckTeamMODEL tt = new TruckTeamMODEL()
            {
                //车队名称
                TeamName = tname,
                //车队负责人
                Leader = lname,
                //备注
                Remark = rt,
                //添加的当前时间
                CheckInTime = Convert.ToDateTime(time),
                //修改的当前的时间
                AlterTime = Convert.ToDateTime(time)
            };
            //定义一个int类型接收BLL层的车队信息
            int result = truck.UInsertTruckTeam(tt);
            //判断信息是否为0，不为0添加成功，否则添加失败
            if (result > 0)
            {
                //跳转页面到用户信息
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('添加成功！');location.href='TruckTeamInfo.aspx';</script>");
            }
            else
            {
                lable.Text = "添加失败！";
            }
        }
    }
}